import java.awt.print.Book;
import java.lang.invoke.SwitchPoint;
import java.lang.reflect.Array;
import java.util.IllegalFormatCodePointException;
import java.util.Scanner;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter.DEFAULT;

public class Apr26 {
static String userinfo[][]=new String[100][4];
static String BookInfo[][]=new String[100][5];
static String PressInfo[][]=new String[100][3];
static Scanner arr =new Scanner(System.in);

public static void main(String[] args) {
// TODO 自动生成的方法存根
initialize();//初始化
head();//登录--注册
}

private static void initialize() {//初始化
userinfo [0] [0]="软件部";
userinfo [0] [1]="软件开发员";
userinfo [0] [2]="name1";
userinfo [0] [3]="123";

userinfo [1] [0]="测试部";
userinfo [1] [1]="测试员";
userinfo [1] [2]="name2";
userinfo [1] [3]="123";

userinfo [2] [0]="测试部";
userinfo [2] [1]="测试员";
userinfo [2] [2]="admin";
userinfo [2] [3]="123";

BookInfo[0][0]="A1111";
BookInfo[0][1]="白夜行";
BookInfo[0][2]="1";
BookInfo[0][3]="cs1";
BookInfo[0][4]="1";

BookInfo[1][0]="B2222";
BookInfo[1][1]="三国演义";
BookInfo[1][2]="2";
BookInfo[1][3]="cs2";
BookInfo[1][4]="2";

BookInfo[1][0]="C3333";
BookInfo[1][1]="水浒传";
BookInfo[1][2]="3";
BookInfo[1][3]="cs3";
BookInfo[1][4]="3";

PressInfo[0][0]="中华书局";
PressInfo[0][1]="北京市王府井大街36号";
PressInfo[0][2]="张三";

PressInfo[1][0]="作家出版社";
PressInfo[1][1]="香港九龙荷李活商业中心8楼";
PressInfo[1][2]="李四";
}
private static void head() {// 登录--注册
System.out.println("欢迎来到闽大图书管理系统！");
System.out.println("1.登录 2.注册");
int a= arr.nextInt();
switch(a) {
case 1:
enter();
break;
case 2:
register();
break;
}

}

private static void enter() {//登录
System.out.println("请输入用户名：");
String usesrName=arr.next();
System.out.println("请输入密码：");
String parkword=arr.next();
boolean judge=false;

for (int i = 0; i < userinfo.length; i++) {
if (usesrName.equals(userinfo[i][2]) && parkword.equals(userinfo[i][3])) {
judge=true;
break;
}
}
if (judge) {
System.out.println("登录成功！");
System.out.println(usesrName+","+"欢迎来到闽大图书管理系统！");
LibraryMM();
}else {
System.out.println("用户名或密码错误！请重新登录！");
head();
}

}


private static void LibraryMM() {//图书管理系统
System.out.println("请输入数字进行选择：1 图书管理  2 出版社管理  3 退出登录  4 退出系统");
int a= arr.nextInt();
switch(a) {
case 1:
BookManage();//图书管理
break;
case 2:
publishingHouse();//出版社管理
case 3:
head();//出版设管理
break;
case 4:
System.exit(0);//退出系统
break;
}

}

private static void publishingHouse() {//出版设管理
System.out.println("请输入：1.增加 2.删除 3.更新 4.根据出版社名称查询 5.查询所有出版社 6.返回上一级菜单");
int a= arr.nextInt();
switch(a) {
case 1://增加
increase2();
break;
case 2://删除
remove2();
break;
case 3://更新
update2();
break;
case 4://查询
NameQuery();
case 5:
System.out.println("出版社名称      地址    联系人");
for (int i = 0; i < PressInfo.length; i++) {
if(PressInfo[i][0]==null) {
break;
}

for (int j = 0; j < PressInfo[i].length; j++) {
System.out.print(PressInfo[i][j]+"  ");
}
System.out.println();
}
case 6:
LibraryMM();
break;
}
}

private static void BookManage() {//图书管理
System.out.println("请输入：1.增加 2.删除 3.更新 4.查询 5.返回上一级菜单");
int a= arr.nextInt();
switch(a) {
case 1://增加
increase();
break;
case 2://删除
remove();
case 3://更新
update();
break;
case 4://查询
inquire();
case 5:
LibraryMM();
break;
}

}
private static void NameQuery() {
System.out.println("请输入出版社名称：");
String name=arr.next();
for (int i = 0; i < PressInfo.length; i++) {
if (name.equals(PressInfo[i][0])) {
System.out.println("出版社名称："+name);
System.out.println("出版社地址："+PressInfo[i][1]);
System.out.println("出版社联系人："+PressInfo[i][2]);
LibraryMM();
break;
}else {
System.out.println("请输入正确的出版社名称");
publishingHouse();
}
}
}
private static void update2() {//出版社更新
System.out.println("请输入要更新的出版社名称：");
String updateName=arr.next();           
      for (int i = 0; i < PressInfo.length; i++) {
if (updateName.equals(PressInfo[i][0])) {
System.out.println("请输入要更新的地址：");
String newddress =arr.next();
System.out.println("请输入要更新的联系人姓名：");
String newName=arr.next();
System.out.println("更新成功");
System.out.println("出版社名称      地址                            联系人");
System.out.println(updateName+"      "+newddress+"                 "+newName);
int index=-1;
for (int j = 0; j < PressInfo.length; j++) {
if(userinfo[j][0]==null) {
index=j;
break;
}
}
PressInfo[index][1]=newddress;
PressInfo[index][2]=newName;
LibraryMM();
}else {
System.out.println("没查找到这个出版社，请重新输入");
LibraryMM();
}
}


}

private static void remove2() {//出版社删除
System.out.println("请输入要删除的出版社名称：");
String delName=arr.next();
isExist(PressInfo, 0, delName);
int index=-1;
for (int i = 0; i < PressInfo.length; i++) {
if (delName.equals(PressInfo[i][0])) {
index=i;
break;
}
}

PressInfo[index][0]=null;
PressInfo[index][1]=null;
PressInfo[index][2]=null;
System.out.println("删除成功!");
LibraryMM();

}

private static void increase2() {//出版社增加
	int index=-1;
	for (int i = 0; i < PressInfo.length; i++) {
		if(PressInfo[i][0]==null) {
			index=i;
			break;
		}
		
	}
System.out.println("请输入出版社名称：");
PressInfo[index][0]=arr.next();
System.out.println("请输入出版社地址：");
PressInfo[index][1]=arr.next();
System.out.println("请输入出版社联系人：");
PressInfo[index][2]=arr.next();
System.out.println("出版社添加成功");
LibraryMM();

}
private static void inquire() {//查询
System.out.println("请输入查询种类：1.isbn 2.书名（模糊） 3.出版社 4. 作者 5. 价格范围 6.查询所有 7.返回上一级 ");
int a=arr.nextInt();
switch (a) {
case 1:
System.out.println("请输入ISBN号：");
String isbn=arr.next();
for (int i = 0; i < BookInfo.length; i++) {
if (isbn.equals(BookInfo[i][0])) {
System.out.println("ISBN    书名        价格           出版社         作者");
System.out.print(BookInfo[i][0]);
System.out.print("   ");
System.out.print(BookInfo[i][1]);
System.out.print("   ");
System.out.print(BookInfo[i][2]);
System.out.print("   ");
System.out.print(BookInfo[i][3]);
System.out.print("   ");
System.out.print(BookInfo[i][4]);
System.out.println();
inquire();
break;
}else {
System.out.println("请输入正确的ISBN");
inquire();
}
}
break;
case 2:
System.out.println("请输入书名：");
String book=arr.next();
for (int i = 0; i < BookInfo.length; i++) {
if (BookInfo!=null  && BookInfo[i][1].indexOf(book)!=-1) {
System.out.println("ISBN    书名        价格           出版社         作者");
System.out.print(BookInfo[i][0]);
System.out.print("   ");
System.out.print(BookInfo[i][1]);
System.out.print("   ");
System.out.print(BookInfo[i][2]);
System.out.print("   ");
System.out.print(BookInfo[i][3]);
System.out.print("   ");
System.out.print(BookInfo[i][4]);
System.out.println();
inquire();
break;
}else {
System.out.println("请输入正确的书名");
inquire();
}
}
break;
case 3:
	PressInquiry();
//System.out.println("请输入出版社：");
//String press=arr.next();
//for (int i = 0; i < PressInfo.length; i++) {
//if (press.equals(BookInfo[i][2])) {
//System.out.println("ISBN    书名        价格           出版社         作者");
//System.out.print(BookInfo[i][0]);
//System.out.print("   ");
//System.out.print(BookInfo[i][1]);
//System.out.print("   ");
//System.out.print(BookInfo[i][2]);
//System.out.print("   ");
//System.out.print(BookInfo[i][3]);
//System.out.print("   ");
//System.out.print(BookInfo[i][4]);
//System.out.println();
//inquire();
//break;
//}else {
//System.out.println("请输入正确的出版社");
//inquire();
//}
//}
break;
case 4:
System.out.println("请输入作者：");
String worker=arr.next();
for (int i = 0; i < BookInfo.length; i++) {
if (worker.equals(BookInfo[i][3])) {
System.out.println("ISBN    书名        价格           出版社         作者");
System.out.print(BookInfo[i][0]);
System.out.print("   ");
System.out.print(BookInfo[i][1]);
System.out.print("   ");
System.out.print(BookInfo[i][2]);
System.out.print("   ");
System.out.print(BookInfo[i][3]);
System.out.print("   ");
System.out.print(BookInfo[i][4]);
System.out.println();
inquire();
break;
}else {
System.out.println("请输入正确的作者");
inquire();
}
}

break;
case 5:
System.out.println("请输入查询的价格区间：");
double money1=arr.nextDouble();
double money2=arr.nextDouble();
for (int i = 0; i < BookInfo.length; i++) {
double price = Double.parseDouble(BookInfo[i][4]);
if (money1<=price && money2>=price) {
System.out.println("ISBN    书名        价格           出版社         作者");
System.out.print(BookInfo[i][0]);
System.out.print("   ");
System.out.print(BookInfo[i][1]);
System.out.print("   ");
System.out.print(BookInfo[i][2]);
System.out.print( "   ");
System.out.print(BookInfo[i][3]);
System.out.print("   ");
System.out.print(BookInfo[i][4]);
System.out.println();
inquire();
break;
}
}

break;
case 6:
System.out.println("ISBN    书名        价格      出版社    作者");
for (int i = 0; i < BookInfo.length; i++) {
if(BookInfo[i][0]==null) {
break;
}

for (int j = 0; j < BookInfo[i].length; j++) {
System.out.print(BookInfo[i][j]+"  ");
}
System.out.println();
}

break;
case 7:
BookManage() ;
break;

default:
break;
}
}

private static void PressInquiry() {
	// 出版社查询
			
			String[][] pubs = new String[PressInfo.length][3];
			
			
			for (int i = 0; i < pubs.length; i++) {
				if (PressInfo[i][0]!=null) {
					pubs[i] = PressInfo[i];
				}
			}
			for (int i = 0; i < pubs.length; i++) {
				if (pubs[i][0]!=null) {
					System.out.print((i+1)+"."+pubs[i][0]+" ");
				}
			}
			System.out.println();
			System.out.println("请选择出版社");
			int key = arr.nextInt();
			System.out.println("ISBN\t书名\t价格\t出版社\t作者");
			for (int i = 0; i < BookInfo.length; i++) {
				if (pubs[key-1][0].equals(BookInfo[i][3])) {
					System.out.println(BookInfo[i][0]+"\t"+BookInfo[i][1]+"\t"+BookInfo   [i][2]
							+"\t"+BookInfo[i][3]+"\t"+BookInfo[i][4]);
				}
			}
}

private static void update() {//更新
System.out.println("请输入ISBN号：");
String updateISBN=arr.next();           
      for (int i = 0; i < BookInfo.length; i++) {
if (updateISBN.equals(BookInfo[i][0])) {
System.out.println("请输入新的书名：");
String newName =arr.next();
System.out.println("请输入新的价格：");
String newMoney=arr.next();
System.out.println("请输入新的出版社：");
String newpublishing=arr.next();
System.out.println("请输入新的作者：");
String newWorker=arr.next();
int index=-1;
for (int j = 0; j < BookInfo.length; j++) {
if(userinfo[j][0]==null) {
index=j;
break;
}
}
userinfo[index][1]=newName;
userinfo[index][2]=newMoney;
userinfo[index][3]=newpublishing;
userinfo[index][4]=newWorker;
}else {
System.out.println("没查找到这个ISBN，请重新输入");
 BookManage() ;
}
}

}

private static void remove() {//删除
System.out.println("请输入要删除的书本名称：");
String delBook=arr.next();
int index=-1;
for (int i = 0; i < BookInfo.length; i++) {
if (delBook.equals(BookInfo[i][1])) {
index=i;
break;
}
}
BookInfo[index][0]=null;
BookInfo[index][1]=null;
BookInfo[index][2]=null;
BookInfo[index][3]=null;
BookInfo[index][4]=null;
System.out.println("删除成功!");
BookManage();
}

private static void increase() {//增加
int index=-1;
for (int i = 0; i < BookInfo.length; i++) {
if(BookInfo[i][0]==null) {
index=i;
break;
}

}
System.out.println("请输入图书ISBN:");
String ISBN=arr.next();
for (int i = 0; i < BookInfo.length; i++) {
if (ISBN.equals(BookInfo[i][0])) {
System.out.println("图书已存在");
BookManage();
}else {
BookInfo[index][0]=ISBN;
System.out.println("请输入书名:");
BookInfo[index][1]=arr.next();
System.out.println("请输入价格:");
BookInfo[index][2]=arr.next();
System.out.println("请输入出版社:");
BookInfo[index][3]=arr.next();
System.out.println("请输入作者:");
BookInfo[index][4]=arr.next();
System.out.println("添加成功！");
}

}


BookManage();

}

private static void register() {//注册
System.out.println("请输入所属部门：");
String apartment =arr.next();
System.out.println("请输入用户角色：");
String name =arr.next();
System.out.println("请输入用户名：");
String user =arr.next();
System.out.println("请输入密码：");
String password =arr.next();
System.out.println("注册成功！");
System.out.println(user+","+"欢迎来到闽大图书管理系统！");

int index=-1;
for (int i = 0; i < userinfo.length; i++) {
if(userinfo[i][0]==null) {
index=i;
break;
}
}
userinfo[index][0]=apartment;
userinfo[index][1]=name;
userinfo[index][2]=user;
userinfo[index][3]=password;
head();
}
private static  boolean isExist(String[][] arr,int index,String isbn) {
boolean flag=false;
for (int i = 0; i < arr.length; i++) {
if (isbn.equals(BookInfo[i][2])) {
flag=true;
break;
}
}
return flag;
}


}